<?php
namespace app\index\model;
use think\Model as UserModel;
use traits\model\SoftDelete;
use think\Db;
use think\Validate;
class User extends UserModel
{
	
	public function logings($username)
	{
		$result = $this->name('user')->where('username','=',$username)->find();
		return $result;
		if($result){
			return true;
		}else{
			return false;
		}
		
	}
	public function reg($data)
	{

		$result = $this->name('user')->insert($data);
		if($result){
			return true;
		}else{
			return false;
		}
		//return $this->getLastSql();
		
	}
	public function check($username)
	{
		$result = Db::table('mall_user')->where('username','=',$username)->find();
		if($result){
			return '此昵称已存在';
		}else{
			return true;
		}

	}
	public function getInfo($username)
	{
		return $this->table('mall_user')->where('username','=',$username)->find();
	}
	public function updateInfo($username,$data)
	{
		 return $this->table('mall_user')->where('username','=',$username)->update($data);
		 //return $this->getLastSql();
	}
	public function updatePass($username,$data)
	{
		return $this->table('mall_user')->where('username','=',$username)->update($data);
	}
	public function payPassword($username,$data)
	{
		return $this->table('mall_user')->where('username','=',$username)->update($data);
	}
	public function getCollection($uid)
	{
		 return $this->table('mall_collection')->where('uid','=',$uid)->select();
		  $this->getLastSql();
	}
	public function getImage($pid)
	{
		return $this->table('mall_image')->where('pid','=',$pid)->find();
	}
	public function getProduct($pid)
	{
		return $this->table('mall_product')->where('pid','=',$pid)->find();
	}
	public function deteleCol($pid)
	{
		 return $this->table('mall_collection')->where('pid','=',$pid)->delete();
		  //$this->getLastSql();
	}
	public function deteleFoot($name)//删除浏览的商品
	{
		return $this->table('mall_foot')->where('name','=',$name)->delete();
		 //$this->getLastSql();
	}
	public function getName($pid)//获取商品名字
	{
		return $this->table('mall_product')->where('pid','=',$pid)->select();
	}
	public function getUid($username)
	{
		return $this->table('mall_user')->where('username','=',$username)->select();
		 //$this->getLastSql();
	}
	public function getCol($uid)
	{
		return $this->table('mall_foot')->where('uid','=',$uid)->select();
	}
	public function getProInfo($pname)
	{
		return $this->table('mall_product')->where('name','=',$pname)->select();
	}
	public function getProImg($pid)
	{
		return $this->table('mall_image')->where('pid','=',$pid)->select();
	}
	public function getAdd($uid)
	{
		return $this->table('mall_address')->where('uid','=',$uid)->select();
	}
	public function add($data)
	{
		return $this->table('mall_address')->insert($data);
		  //$this->getLastSql();
	}
	public function delAdd($aid)
	{
		return $this->table('mall_address')->where('aid','=',$aid)->delete();
	}
	public function province()//省份
    {
      return [
        '1'=> '浙江省',
        '2'=> '湖北省',
        '3'=> '山西省'
      ];
    }
    public function city()//城市
    {
      return[
        '1'=> '温州市',
        '2'=> '武汉市',
        '3'=> '太原市'
      ];
    }
    public function country()//区县
    {
      return[
        '1'=> '瑞安区',
        '2'=> '洪山区',
        '3'=> '小店区'
      ];
    }
    public function status()//订单状态
    {
    	return[
    		'1'=>'未付款',
    		'2'=>'已支付',
    		'3'=>'未发货',
    		'4'=>'已配货',
    		'5'=>'在路上',
    		'6'=>'已送达/未签收',
    		'7'=>'已送达/签收',
    		'8'=>'未评论',
    		'9'=>'评论完成'
    	];
    }
    public function question()//咨询问题
    {
    	return [
    		'1'=>'产品问题',
    		'2'=>'促销问题',
    		'3'=>'支付问题',
    		'4'=>'退款问题',
    		'5'=>'配送问题',
    		'6'=>'售后问题',
    		'7'=>'发票问题',
    		'8'=>'退换货问题',
    		'9'=>'其他'
    	];
    }
    public function type()//优惠券类型
    {
    	return [
    		'1'=>'现金券',
    		'2'=>'运费券'
    	];
    }
    public function point()//评论等级
    {
    	return [
    		'1'=>'好评',
    		'2'=>'中评',
    		'3'=>'差评',
    	];
    }
    public function getOrder($uid)
    {
    	return $this->table('mall_order')->where('uid','=',$uid)->select();
    }
    public function getOrderInfo($pid)
    {
    	return $this->table('mall_product')->where('pid','=',$pid)->select();
    }
    public function deteleOrder($oid)
    {
    	return $this->table('mall_order')->where('oid','=',$oid)->delete();
    } 
    public function addSul($data)
    {
    	return $this->table('mall_news')->insert($data);
    }
    public function getType($uid)
    {
    	return $this->table('mall_coupons')->where('uid','=',$uid)->select();
    }
    public function getCoupon($typeid)//优惠券类型
    {
    	return $this->table('mall_coupon')->where('type_id','=',$typeid)->select();
    }
    public function updateAble($id,$data)
    {
    	 return $this->table('mall_coupon')->where('id','=',$id)->update($data);
    	 
    }
    public function addCom($data)
    {
    	return $this->table('mall_comment')->insert($data);
    }
    public function getCom($uid)
    {
    	return $this->table('mall_comment')->where('uid','=',$uid)->select();
    }
    public function getPro($pid)
    {
    	return $this->table('mall_product')->where('pid','=',$pid)->select();
    }
}